package com.bstek.uflo.form.controller;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.web.servlet.ModelAndView;

import com.bstek.dorado.web.resolver.AbstractResolver;
import com.bstek.uflo.form.action.Action;

/**
 * @author Jacky.gao
 * @since 2013年11月12日
 */
public class ListActionController extends AbstractResolver {

	@Override
	protected ModelAndView doHandleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
		List<List<String>> list=new ArrayList<List<String>>();
		Map<String,Action> map=this.getApplicationContext().getParent().getBeansOfType(Action.class);
		for(String name:map.keySet()){
			List<String> actions=new ArrayList<String>();
			Action action=map.get(name);
			actions.add(action.getName());
			actions.add(name);
			list.add(actions);
		}
		ObjectMapper mapper=new ObjectMapper();
		response.setContentType("text/json");  
		response.setCharacterEncoding("UTF-8");  
		OutputStream out=response.getOutputStream();
		try{
			mapper.writeValue(out, list);
		}finally{
			out.flush();
			out.close();
		}
		return null;
	}
}
